package com.fyl.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fyl.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class ResponseController2 {

    @GetMapping("/ajax/res1")
    @ResponseBody
    public String res1(){
        return "res1";
    }

    @GetMapping("/ajax/res2")
    @ResponseBody
    public String res2() throws JsonProcessingException {
        User user = new User();
        user.setUsername("lele");
        user.setAge(18);
        ObjectMapper objectMapper = new ObjectMapper();
        String s = objectMapper.writeValueAsString(user);
        return s;
    }

    @GetMapping("/ajax/res3")
    //@ResponseBody
    public User res3() throws JsonProcessingException {
        System.out.println("1111 = " + 1111);
        User user = new User();
        user.setUsername("lele");
        user.setAge(18);
        return user;
    }
}
